package com.aidex.system.service.impl;

import com.aidex.common.core.service.BaseServiceImpl;
import com.aidex.system.domain.WordMatchTime;
import com.aidex.system.mapper.WordMatchTimeMapper;
import com.aidex.system.service.WordMatchTimeService;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 大数据分词匹配次数Service业务层处理
 * @author jmy
 * @email jmyinjg@163.com
 * @date 2021-11-01
 */
@Service
@Transactional(readOnly = false)
public class WordMatchTimeServiceImpl extends BaseServiceImpl<WordMatchTimeMapper, WordMatchTime> implements WordMatchTimeService
{
    private static final Logger log = LoggerFactory.getLogger(WordMatchTimeServiceImpl.class);

    /**
     * 获取单条数据
     * @param wordMatchTime 大数据分词匹配次数
     * @return 大数据分词匹配次数
     */
    @Override
    public WordMatchTime get(WordMatchTime wordMatchTime)
    {
        WordMatchTime dto = super.get(wordMatchTime);
        return dto;
    }

    /**
     * 获取单条数据
     * @param id 大数据分词匹配次数id
     * @return 大数据分词匹配次数
     */
    @Override
    public WordMatchTime get(String id)
    {
        WordMatchTime dto = super.get(id);
        return dto;
    }


    /**
     * 查询大数据分词匹配次数列表
     * @param wordMatchTime 大数据分词匹配次数
     * @return 大数据分词匹配次数
     */
    @Override
    public List<WordMatchTime> findList(WordMatchTime wordMatchTime)
    {
        return super.findList(wordMatchTime);
    }

    /**
     * 分页查询大数据分词匹配次数列表
     * @param wordMatchTime 大数据分词匹配次数
     * @return 大数据分词匹配次数
     */
    @Override
    public PageInfo<WordMatchTime> findPage(WordMatchTime wordMatchTime)
    {
        return super.findPage(wordMatchTime);
    }

    /**
     * 保存大数据分词匹配次数
     * @param wordMatchTime
     * @return 结果
     */
    @Override
    public boolean save(WordMatchTime wordMatchTime)
    {
        return super.save(wordMatchTime);
    }


    /**
     * 删除大数据分词匹配次数信息
     * @param wordMatchTime
     * @return 结果
     */
    @Override
    public boolean remove(WordMatchTime wordMatchTime)
    {
        return super.remove(wordMatchTime);
    }

    /**
     * 批量删除大数据分词匹配次数
     * @param ids 需要删除的大数据分词匹配次数ID
     * @return 结果
     */
    @Transactional(readOnly = false)
    @Override
    public int deleteWordMatchTimeByIds(String[] ids)
    {
        return mapper.deleteWordMatchTimeByIds(ids);
    }

    @Override
    public WordMatchTime getByWord(String word) {
        WordMatchTime param = new WordMatchTime();
        param.setKeywords(word);
        return this.get(param);
    }

    @Override
    public Boolean checkWord(String word, Integer time) {
        WordMatchTime wordInfo = this.getByWord(word);
        if (wordInfo == null) {
            wordInfo = new WordMatchTime();
            wordInfo.setKeywords(word);
            wordInfo.setMatchTime(1);
            this.save(wordInfo);
            return time == 1;
        }
        wordInfo.setMatchTime(wordInfo.getMatchTime() + 1);
        this.save(wordInfo);
        return wordInfo.getMatchTime() >= time;
    }

}
